<!--
 * @Author: 曹捷
 * @Date: 2020-09-09 21:31:53
 * @LastEditors: 曹捷
 * @LastEditTime: 2020-09-16 21:48:57
 * @Description: file content
-->
<template>
  <obitRadio :dataList="dictList" v-model="dictValue" @change="changeInfo"></obitRadio>
</template>

<script>
import obitRadio from './../obit-radio/obit-radio'
export default {
  props: {
    dictCode: {
      type: String,
    },
    value: {
      type: [Number, String],
    },
  },
  data() {
    return {
      dictList: [],
      dictValue: '',
    }
  },
  watch: {
    value(value) {
      this.initValue()
    },
  },
  components: {
    obitRadio,
  },
  methods: {
    initValue() {
      this.dictValue = this.value
    },
    changeInfo(e) {
      this.$emit('input', e)
      this.$emit('change', e)
    },
    initInfo() {
      let cach = this.$app.cachInfo(`dict-${this.dictCode}`)
      if (cach.get()) {
        this.dictList = cach.get()
      } else {
        this.$http.getDict(this.dictCode).then((res) => {
          this.dictList = res
          cach.set(res)
        })
      }
    },
  },
  mounted() {
    this.initInfo()
    this.initValue()
  },
}
</script>

<style lang="scss"></style>
